package io.renren.modules.shop.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.common.utils.R;
import io.renren.modules.shop.entity.UserAndCoupon;
import io.renren.modules.shop.service.UserAndCouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("user_and_coupon")
@Api(value = "优惠券用户controller", tags = {("优惠券接口")})
public class UserAndCouponController {
    @Autowired
    private UserAndCouponService userAndCouponService;

    @ApiOperation(value = "查询分页")
    @PostMapping("page")
    public R getPage(@RequestBody UserAndCoupon userAndCoupon, @RequestParam Integer size, @RequestParam Integer page) {
        IPage<UserAndCoupon> iPage = new Page<>(page,size);
        IPage<UserAndCoupon> goodsCouponIPage = userAndCouponService.page(iPage, new QueryWrapper<>(userAndCoupon));
        List<UserAndCoupon> list = goodsCouponIPage.getRecords();
        return R.ok().put("page",list);
    }


    @ApiOperation(value = "查询所有数据")
    @PostMapping("list")
    public R getList(@RequestBody UserAndCoupon userAndCoupon) {
        List<UserAndCoupon> list = userAndCouponService.list(new QueryWrapper<>(userAndCoupon));
        return R.ok().put("list",list);
    }

    @ApiOperation(value = "根据ids删除记录")
    @PostMapping("delete")
    public R del(@RequestParam Integer[] ids) {
        boolean flag = userAndCouponService.removeByIds(Arrays.asList(ids));
        return R.ok().put("flag",flag);
    }


}
